package dao;

import org.apache.ibatis.annotations.*;
import pojo.HospitalBed;

import java.util.List;

@Mapper
public interface HospitalBedMapper {
    // 查询所有病床信息
    @Select("SELECT * FROM hospital_beds")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "bedType", column = "bed_type"),
            @Result(property = "bedAddress", column = "bed_address"),
            @Result(property = "isAvailable", column = "is_available"),
            @Result(property = "patientName", column = "patient_name"),
            @Result(property = "patientId", column = "patient_id"),
            @Result(property = "guardianPhone", column = "guardian_phone"),
            @Result(property = "checkInTime", column = "check_in_time"),
            @Result(property = "expectedCheckOutTime", column = "expected_check_out_time"),
            @Result(property = "touxiang", column = "bed_touxiang")
    })
    List<HospitalBed> findAllHospitalBeds();

    // 根据ID查询病床信息
    @Select("SELECT * FROM hospital_beds WHERE id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "bedType", column = "bed_type"),
            @Result(property = "bedAddress", column = "bed_address"),
            @Result(property = "isAvailable", column = "is_available"),
            @Result(property = "patientName", column = "patient_name"),
            @Result(property = "patientId", column = "patient_id"),
            @Result(property = "guardianPhone", column = "guardian_phone"),
            @Result(property = "checkInTime", column = "check_in_time"),
            @Result(property = "expectedCheckOutTime", column = "expected_check_out_time"),
            @Result(property = "touxiang", column = "bed_touxiang")
    })
    HospitalBed findHospitalBedById(Integer id);

    // 添加病床
    @Insert("INSERT INTO hospital_beds(bed_type, bed_address, is_available, patient_name, patient_id, guardian_phone, check_in_time, expected_check_out_time , touxiang) " +
            "VALUES(#{bedType}, #{bedAddress}, #{isAvailable}, #{patientName}, #{patientId}, #{guardianPhone}, #{checkInTime}, #{expectedCheckOutTime},#{touxiang})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertHospitalBed(HospitalBed hospitalBed);

    // 更新病床信息
    @Update("UPDATE hospital_beds SET bed_type=#{bedType}, bed_address=#{bedAddress}, is_available=#{isAvailable}, " +
            "patient_name=#{patientName}, patient_id=#{patientId}, guardian_phone=#{guardianPhone}, " +
            "check_in_time=#{checkInTime}, expected_check_out_time=#{expectedCheckOutTime}, " +
            "touxiang = #{touxiang} WHERE id=#{id}")
    void updateHospitalBed(HospitalBed hospitalBed);

    // 删除病床
    @Delete("DELETE FROM hospital_beds WHERE id = #{id}")
    void deleteHospitalBed(Integer id);
}